class rankItem extends eui.ItemRenderer{
	private lb_rank:eui.Label;
	private img_icon:eui.Image;
	private lb_name:eui.Label;
	private lb_money:eui.Label;
	private rank_bg:eui.Image;

	public constructor() {
		super();
		this.skinName = "RankItem";
	}

	protected childrenCreated():void{
		super.childrenCreated();
	}

	protected dataChanged(){
		this.updateItem();
	}

	public updateItem()
	{
		if(this.data)
		{
			let name = (this.data['nick_name'] == null) ? "你猜我是谁": this.data['nick_name'];
			let icon = this.data['avatar_url'] == null ? "normal_icon_jpg": this.data['avatar_url'];

			if(name == "")
			{
				name = "兰絮因果";
			}

			if(icon == "")
			{
				icon = "normal_icon_jpg";
			}
			
			let maxScore = this.data['max_score'];

			if(this.data.rank <=3)
			{
				this.rank_bg.source = 'rank_'+this.data.rank+'_png';
			}
			else
			{
				this.rank_bg.source = 'rank_4_png';
			}
			this.lb_rank.text = this.data.rank;

			this.lb_name.text = GameUtil.getNameSlice(name);
			this.img_icon.source = icon;
			let scoreStr = maxScore;
			if(maxScore >= 1000)
			{
				scoreStr = (Math.floor(maxScore / 1000) << 0) + 'k';
			}
			else if(maxScore >= 10000)
			{
				scoreStr = (Math.floor(maxScore / 10000) << 0) + 'w';
			}

			if(this.data.type == 0)
			{
				this.lb_money.text = '$'+scoreStr;
			}
			else
			{
				this.lb_money.text = scoreStr+'m';
			}
		}
	}
}

window['rankItem'] = rankItem;